package cn.client.data.remoteData.bean

import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonQualifier
import com.squareup.moshi.ToJson
import java.text.SimpleDateFormat
import java.util.Locale

/**
 * 时间戳转日期字符串
 */
@Retention(AnnotationRetention.RUNTIME)
@JsonQualifier
annotation class DateText

class DateTextAdapter {
    companion object {
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
    }
    @ToJson
    fun toJson(@DateText text: String): Long {
        return sdf.parse(text).time
    }
    @FromJson
    @DateText
    fun fromJson(timestamp: Long): String {
        return sdf.format(timestamp)
    }
}
